var express = require('express')
    , route = express.Router()
    , logger = require('log4js').getLogger('user.index.js');

let stock = require('../../controller/stock');

route.use((req, res, next) => {
    logger.info(req.url);
    next();
});

// 以后在这里处理入参，并返回 res
route.get('/list', (req, res) => {
    stock.getList(req, function (err, data) {
        if (err) {
            return res.send(err);
        }
        res.send(data);
    });
    // res.send({ name: 'ha', number: 1223 });
});

route.get('/add/:name', (req, res) => {
    var test = new user({ user_id: Date.now(), user_name: req.params.name });
    test.save(err => {
        if (err) return res.send(err);
        user.findOne({ "user_name": req.params.name }, (err, rel) => {
            if (err) return res.send(err);
            res.send(rel);
        });
    });

    // res.send('user index page');
});

route.get('/about', (req, res) => {
    res.send('about user');
});

module.exports = route;